<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>headerformatter.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_editor_plugins_headerformatter.js.html">headerformatter.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Handles applying header styles to text.
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.editor.plugins.HeaderFormatter&#39;);
<a name="line21"></a>
<a name="line22"></a>goog.require(&#39;goog.editor.Command&#39;);
<a name="line23"></a>goog.require(&#39;goog.editor.Plugin&#39;);
<a name="line24"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line25"></a>
<a name="line26"></a>
<a name="line27"></a>
<a name="line28"></a>/**
<a name="line29"></a> * Applies header styles to text.
<a name="line30"></a> * @constructor
<a name="line31"></a> * @extends {goog.editor.Plugin}
<a name="line32"></a> * @final
<a name="line33"></a> */
<a name="line34"></a>goog.editor.plugins.HeaderFormatter = function() {
<a name="line35"></a>  goog.editor.Plugin.call(this);
<a name="line36"></a>};
<a name="line37"></a>goog.inherits(goog.editor.plugins.HeaderFormatter, goog.editor.Plugin);
<a name="line38"></a>
<a name="line39"></a>
<a name="line40"></a>/** @override */
<a name="line41"></a>goog.editor.plugins.HeaderFormatter.prototype.getTrogClassId = function() {
<a name="line42"></a>  return &#39;HeaderFormatter&#39;;
<a name="line43"></a>};
<a name="line44"></a>
<a name="line45"></a>// TODO(user):  Move execCommand functionality from basictextformatter into
<a name="line46"></a>// here for headers.  I&#39;m not doing this now because it depends on the
<a name="line47"></a>// switch statements in basictextformatter and we&#39;ll need to abstract that out
<a name="line48"></a>// in order to seperate out any of the functions from basictextformatter.
<a name="line49"></a>
<a name="line50"></a>
<a name="line51"></a>/**
<a name="line52"></a> * Commands that can be passed as the optional argument to execCommand.
<a name="line53"></a> * @enum {string}
<a name="line54"></a> */
<a name="line55"></a>goog.editor.plugins.HeaderFormatter.HEADER_COMMAND = {
<a name="line56"></a>  H1: &#39;H1&#39;,
<a name="line57"></a>  H2: &#39;H2&#39;,
<a name="line58"></a>  H3: &#39;H3&#39;,
<a name="line59"></a>  H4: &#39;H4&#39;
<a name="line60"></a>};
<a name="line61"></a>
<a name="line62"></a>
<a name="line63"></a>/**
<a name="line64"></a> * @override
<a name="line65"></a> */
<a name="line66"></a>goog.editor.plugins.HeaderFormatter.prototype.handleKeyboardShortcut = function(
<a name="line67"></a>    e, key, isModifierPressed) {
<a name="line68"></a>  if (!isModifierPressed) {
<a name="line69"></a>    return false;
<a name="line70"></a>  }
<a name="line71"></a>  var command = null;
<a name="line72"></a>  switch (key) {
<a name="line73"></a>    case &#39;1&#39;:
<a name="line74"></a>      command = goog.editor.plugins.HeaderFormatter.HEADER_COMMAND.H1;
<a name="line75"></a>      break;
<a name="line76"></a>    case &#39;2&#39;:
<a name="line77"></a>      command = goog.editor.plugins.HeaderFormatter.HEADER_COMMAND.H2;
<a name="line78"></a>      break;
<a name="line79"></a>    case &#39;3&#39;:
<a name="line80"></a>      command = goog.editor.plugins.HeaderFormatter.HEADER_COMMAND.H3;
<a name="line81"></a>      break;
<a name="line82"></a>    case &#39;4&#39;:
<a name="line83"></a>      command = goog.editor.plugins.HeaderFormatter.HEADER_COMMAND.H4;
<a name="line84"></a>      break;
<a name="line85"></a>  }
<a name="line86"></a>  if (command) {
<a name="line87"></a>    this.getFieldObject().execCommand(
<a name="line88"></a>        goog.editor.Command.FORMAT_BLOCK, command);
<a name="line89"></a>    // Prevent default isn&#39;t enough to cancel tab navigation in FF.
<a name="line90"></a>    if (goog.userAgent.GECKO) {
<a name="line91"></a>      e.stopPropagation();
<a name="line92"></a>    }
<a name="line93"></a>    return true;
<a name="line94"></a>  }
<a name="line95"></a>  return false;
<a name="line96"></a>};
</pre>


</body>
</html>
